<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-form-item label="城市服务商" style="margin-right: 10px" v-has="'xhdjTechnicianEvaluation:select'">
          <serveSelect @selectClick="selectClick" :value="queryParam.agencyCode"></serveSelect>
        </a-form-item>
        <a-form-item label="评价等级" style="margin-right: 10px">
          <a-select
            v-model="queryParam.evaluateType"
            style="width: 120px"
            :options="[
              { label: '一星', value: '1' },
              { label: '二星', value: '2' },
              { label: '三星', value: '3' },
              { label: '四星', value: '4' },
              { label: '五星', value: '5' }
            ]"
            allowClear
            placeholder="请选择"
          />
        </a-form-item>
        <a-form-item label="订单编号" style="margin-right: 10px">
          <a-input placeholder="请输入标题" v-model="queryParam.orderNo"></a-input>
        </a-form-item>
        <a-form-item label="用户编号" style="margin-right: 10px">
          <a-input placeholder="请输入用户编号" v-model="queryParam.userId"></a-input>
        </a-form-item>
        <a-form-item label="服务技师" style="margin-right: 10px">
          <a-input placeholder="请输入服务技师" v-model="queryParam.coachName"></a-input>
        </a-form-item>
        <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
          <a-button type="primary" @click="addpinlun" icon="plus" style="margin-left: 8px" v-has="'xhdjpinjia:add'"
            >新增评论</a-button
          >

          <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 8px">查询</a-button>
          <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
        </span>
      </a-form>
    </div>
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <a-table
      ref="table"
      size="default"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
    >
      <span slot="evaluateType" slot-scope="text, record">
        <a-rate v-model="record.evaluateType" disabled />
      </span>
      <span slot="skillEvaluateType" slot-scope="text, record">
        <a-rate v-model="record.skillEvaluateType" disabled />
      </span>
      <span slot="action" slot-scope="text, record">
        <a-popconfirm
          title="确定处理吗?"
          @confirm="() => dispose(record)"
          v-if="record.appealStatus == 2"
          v-has="'XhdjUserInfo:chuli'"
        >
          <a>处理</a>
        </a-popconfirm>
        <a-divider type="vertical" v-if="record.appealStatus == 2" v-has="'XhdjUserInfo:chuli'" />

        <a v-has="'evaluate:edit'" @click="handleEdit(record)">编辑</a>
        <a-divider type="vertical" />
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
          <a>删除</a>
        </a-popconfirm>
      </span>
    </a-table>
    <xhdjTechnicianEvaluationModal ref="modalForm" @ok="modalFormOk"></xhdjTechnicianEvaluationModal>
    <xhdjTechnicianEvaluationAdd ref="add" @ok="modalFormOk"></xhdjTechnicianEvaluationAdd>
  </a-card>
</template>

<script>
import { filterObj } from '@/utils/util'
import { getAction, putAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import serveSelect from '@/components/serveSelect.vue'
import xhdjTechnicianEvaluationModal from './modules/xhdjTechnicianEvaluationModal.vue'
import xhdjTechnicianEvaluationAdd from './modules/xhdjTechnicianEvaluationAdd.vue'
export default {
  name: 'UserAnnouncementList',
  mixins: [JeecgListMixin],
  components: {
    xhdjTechnicianEvaluationModal,
    xhdjTechnicianEvaluationAdd,
    serveSelect
  },
  data () {
    return {
      description: '评价列表',
      queryParam: {},
      columns: [
        {
          title: '用户编号',
          align: 'center',
          width: 90,
          dataIndex: 'userId'
        },
        {
          title: '用户名称',
          align: 'center',
          width: 90,
          dataIndex: 'nickName'
        },
        {
          title: '技师编号',
          align: 'center',
          dataIndex: 'coachId'
        },
        {
          title: '服务技师',
          align: 'center',
          dataIndex: 'coachName'
        },
        {
          title: '订单编号',
          align: 'center',
          width: 220,
          dataIndex: 'orderNo'
        },
        {
          title: '评价类型',
          align: 'center',
          dataIndex: 'type',
          customRender: function (type) {
            if (type == '0') {
              return '订单评价'
            } else {
              return '技师回复'
            }
          }
        },
        {
          title: '评价内容',
          align: 'center',
          dataIndex: 'evaluate'
        },
        {
          title: '申诉内容',
          align: 'center',
          dataIndex: 'appealContent'
        },
        {
          title: '服务评分',
          align: 'center',
          width: 170,
          dataIndex: 'evaluateType',
          scopedSlots: { customRender: 'evaluateType' }
        },
        {
          title: '技术评分',
          align: 'center',
          width: 170,
          dataIndex: 'skillEvaluateType',
          scopedSlots: { customRender: 'skillEvaluateType' }
        },
        {
          title: '评价时间',
          align: 'center',
          width: 150,
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 170,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/order/xhdjOrderEvaluate/list',
        editCementSend: '/message/read',
        readAllMsg: '/message/allRead',
        delete: '/order/xhdjOrderEvaluate/delete',
        reject: '/order/xhdjOrderEvaluate/dispose',
        deleteBatch: '/order/xhdjOrderEvaluate/deleteBatch'
      },
      loading: false,
      openPath: '',
      formData: ''
    }
  },
  methods: {
    addpinlun (record) {
      this.$refs.add.edit(record)
      this.$refs.add.title = '新增评论'
    },
    // 处理
    dispose (item) {
      getAction(this.url.reject, { id: item.id }).then(res => {
        if (res.code == 200) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.console.error(res.message)
        }
      })
    },

    handleDetail: function (record) {
      this.$refs.sysAnnouncementModal.detail(record)
      this.$refs.sysAnnouncementModal.title = '查看'
    },
    showAnnouncement (record) {
      var that = this
      getAction(this.url.editCementSend, { id: record.id }).then(res => {
        that.$message.success(res.message)
        that.loadData()
        that.syncHeadNotic()
      })
      // if (record.openType === 'component') {
      //   this.openPath = record.openPage
      //   this.formData = { id: record.busId }
      //   this.$refs.showDynamNotice.detail()
      // } else {
      //   this.$refs.ShowAnnouncement.detail(record)
      // }
    },
    syncHeadNotic (anntId) {
      getAction('sys/annountCement/syncNotic', { anntId: anntId })
    },
    selectClick (value) {
      this.queryParam.agencyCode = value
      this.searchQuery()
    },
    readAll () {
      var that = this
      that.$confirm({
        title: '确认操作',
        content: '是否全部标注已读?',
        onOk: function () {
          getAction(that.url.readAllMsg).then(res => {
            if (res.success) {
              that.$message.success(res.message)
              that.loadData()
              that.syncHeadNotic()
            }
          })
        }
      })
    }
  }
}
</script>
<style scoped>
.ant-row {
  display: flex;
  justify-content: flex-end;
}
.ant-col {
  display: flex;
  justify-content: flex-end;
}
.ant-form {
  display: flex;
}
</style>
